﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraBars;

namespace QLTV.GUI.Forms
{
    public partial class frmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public frmMain()
        {
            InitializeComponent();
            System.Random r = new Random();

            DevExpress.Skins.SkinContainerCollection skinCollection = DevExpress.Skins.SkinManager.Default.Skins;

            DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(skinCollection[r.Next(0, skinCollection.Count)].SkinName);
        }

        private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
            UserControl.ucPhieuMuonSach ucPhieuMuon = new UserControl.ucPhieuMuonSach();
            ucPhieuMuon.Dock = DockStyle.Fill;

            Addtabpage(ucPhieuMuon, "Thông Tin Phiếu Nhập Sách");
            if (!this.xtraTab.IsLoading || this.xtraTab.Visible == false)
            {
                this.xtraTab.Visible = true;
            }
        }
        private void xtraTabControl_CloseButtonClick(object sender, EventArgs e)
        {
            DevExpress.XtraTab.XtraTabControl tabControl = sender as DevExpress.XtraTab.XtraTabControl;
            DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs arg = e as DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs;
            (arg.Page as DevExpress.XtraTab.XtraTabPage).Dispose();
        }
        private void xtraTabControl1_ControlAdded(object sender, ControlEventArgs e)
        {
            xtraTab.SelectedTabPageIndex = xtraTab.TabPages.Count - 1;
        }
        private void Addtabpage(DevExpress.XtraEditors.XtraUserControl frm, string tabname)
        {
            DevExpress.XtraTab.XtraTabPage tab = new DevExpress.XtraTab.XtraTabPage();
            tab.Text = tabname;
            //frm.TopLevel = false;
            frm.Show();
            frm.Parent = tab;
            //tab.Controls.Add(frm);
            bool kt = false;
            foreach (DevExpress.XtraTab.XtraTabPage tabitem in xtraTab.TabPages)
            {
                if (tabitem.Text == tabname)
                {
                    xtraTab.SelectedTabPage = tabitem;
                     
                    kt = true;
                }
            }
            if (!kt)
            {
                xtraTab.TabPages.AddRange(new DevExpress.XtraTab.XtraTabPage[] { tab });
            }
        }

        private void btnDSDG_ItemClick(object sender, ItemClickEventArgs e)
        {
            UserControl.ucDocGia ucDG = new UserControl.ucDocGia();
            ucDG.Dock = DockStyle.Fill;
            Addtabpage(ucDG, "Danh Sách Độc Giả");
            if (!this.xtraTab.IsLoading || this.xtraTab.Visible == false)
            {
                this.xtraTab.Visible = true;
            }
        }

        private void btnThemDG_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmThemDocGia frmThemDG = new frmThemDocGia();
            frmThemDG.ShowDialog();
        }

        private void btnTimDG_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmTimDocGia frmTimDG = new frmTimDocGia();
            frmTimDG.ShowDialog();
        }

        private void btnQuyDinh_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmQuyDinh frmQD = new frmQuyDinh();
            frmQD.ShowDialog();
        }

        private void btnKhoSach_ItemClick(object sender, ItemClickEventArgs e)
        {
            UserControl.ucSach ucS = new UserControl.ucSach();
            ucS.Dock = DockStyle.Fill;
            Addtabpage(ucS, "Thông Tin Sách");
            if (!this.xtraTab.IsLoading || this.xtraTab.Visible == false)
            {
                this.xtraTab.Visible = true;                
            }
        }

        private void btnTheLoai_ItemClick(object sender, ItemClickEventArgs e)
        {
            UserControl.ucTheLoai ucTL = new UserControl.ucTheLoai();
            ucTL.Dock = DockStyle.Fill;
            Addtabpage(ucTL, "Thông Tin Thể Loại");
            if (!this.xtraTab.IsLoading || this.xtraTab.Visible == false)
            {
                this.xtraTab.Visible = true;
            }
        }

        private void btnTacGia_ItemClick(object sender, ItemClickEventArgs e)
        {
            UserControl.ucTacGia ucTG = new UserControl.ucTacGia();
            ucTG.Dock = DockStyle.Fill;
            Addtabpage(ucTG, "Thông Tin Tác Giả");
            if (!this.xtraTab.IsLoading || this.xtraTab.Visible == false)
            {
                this.xtraTab.Visible = true;
            }
        }

        private void btnNXB_ItemClick(object sender, ItemClickEventArgs e)
        {
            UserControl.ucNXB ucNXB = new UserControl.ucNXB();
            ucNXB.Dock = DockStyle.Fill;
            Addtabpage(ucNXB, "Thông Tin Nhà Xuất Bản");
            if (!this.xtraTab.IsLoading || this.xtraTab.Visible == false)
            {
                this.xtraTab.Visible = true;
            }
        }

        private void btnDS_ItemClick(object sender, ItemClickEventArgs e)
        {
            UserControl.ucDauSach ucDS = new UserControl.ucDauSach();
            ucDS.Dock = DockStyle.Fill;
            Addtabpage(ucDS, "Thông Tin Đầu Sách");
            if (!this.xtraTab.IsLoading || this.xtraTab.Visible == false)
            {
                this.xtraTab.Visible = true;
            }
        }

        private void btnLoaiDocGia_ItemClick(object sender, ItemClickEventArgs e)
        {
            UserControl.ucLoaiDocGia ucLDG = new UserControl.ucLoaiDocGia();
            ucLDG.Dock = DockStyle.Fill;
            Addtabpage(ucLDG, "Thông Tin Loại Độc Giả");
            if (!this.xtraTab.IsLoading || this.xtraTab.Visible == false)
            {
                this.xtraTab.Visible = true;
            }
        }

        private void barButtonItem2_ItemClick(object sender, ItemClickEventArgs e)
        {
            UserControl.ucPhieuTraSach ucPhieuTra = new UserControl.ucPhieuTraSach();
            ucPhieuTra.Dock = DockStyle.Fill;
            Addtabpage(ucPhieuTra, "Thông Tin Phiếu Trả Sách");
            if (!this.xtraTab.IsLoading || this.xtraTab.Visible == false)
            {
                this.xtraTab.Visible = true;
            }
        }

        private void barButtonItem3_ItemClick(object sender, ItemClickEventArgs e)
        {
            UserControl.ucQuanLyMuonTra ucPhieuTra = new UserControl.ucQuanLyMuonTra();
            ucPhieuTra.Dock = DockStyle.Fill;
            Addtabpage(ucPhieuTra, "Quản lý mượn trả");
            if (!this.xtraTab.IsLoading || this.xtraTab.Visible == false)
            {
                this.xtraTab.Visible = true;
            }
        }

        private void frmMain_Load(object sender, EventArgs e)
        {

        }

        
    }
}